home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / VALIDATE.PAK / VALIDATX.CPP < prev   
C/C++ Source or Header  |  1997-05-06  |  5KB  |  192 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1993, 1996 by Borland International, All Rights Reserved
  4. //----------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #if !defined(OWL_APPLICAT_H)
  7. # include <owl/applicat.h>
  8. #endif
  9. #if !defined(OWL_DIALOG_H)
  10. # include <owl/dialog.h>
  11. #endif
  12. #if !defined(OWL_FRAMEWIN_H)
  13. # include <owl/framewin.h>
  14. #endif
  15. #if !defined(OWL_EDIT_H)
  16. # include <owl/edit.h>
  17. #endif
  18. #if !defined(OWL_CHECKBOX_H)
  19. # include <owl/checkbox.h>
  20. #endif
  21. #if !defined(OWL_VALIDATE_H)
  22. # include <owl/validate.h>
  23. #endif
  24. #include <string.h>               // For strcpy and strcat
  25. #include <stdlib.h>               // For atoi
  26. #include <ctype.h>                // For isdigit and isalpha
  27. #include "validate.rc"               
  28.  
  29. #define MAXNAMELEN     35
  30. #define MAXSSLEN       12
  31. #define MAXIDLEN       4
  32. #define MAXDEPTLEN     7
  33. #define MAXSECLEN      3
  34. #define MAXCUSTOMLEN   20
  35.  
  36. struct TEmployeeStruct {
  37.   char NameEdit[MAXNAMELEN];
  38.   char SSEdit[MAXSSLEN];
  39.   char IDEdit[MAXIDLEN];
  40.   char DeptEdit[MAXDEPTLEN];
  41.   char SecEdit[MAXSECLEN];
  42.   uint16 FullTime;
  43.   uint16 Perm;
  44.   uint16 Exempt;
  45.   char CustomEdit[MAXCUSTOMLEN];
  46. };
  47.  
  48. //
  49. // class TEmployeeDlg
  50. // ~~~~~ ~~~~~~~~~~~~
  51. class TEmployeeDlg : public TDialog {
  52.   public:
  53.     TEmployeeDlg(TWindow* parent, TResId resId, TEmployeeStruct& transfer);
  54.  
  55.   private:
  56.     void    CmSetCustom();
  57.     TEdit*  CustomEdit;
  58.  
  59.   DECLARE_RESPONSE_TABLE(TEmployeeDlg);
  60. };
  61.  
  62.  
  63. DEFINE_RESPONSE_TABLE1(TEmployeeDlg, TDialog)
  64.   EV_COMMAND(IDC_CUSTOM, CmSetCustom),
  65. END_RESPONSE_TABLE;
  66.  
  67.  
  68. //
  69. //
  70. //
  71. TEmployeeDlg::TEmployeeDlg(TWindow* parent, TResId resid,
  72.   TEmployeeStruct& transfer)
  73. :
  74.   TDialog(parent, resid)
  75. {
  76.   TEdit* edit;
  77.   edit = new TEdit(this, IDC_NAME, sizeof(transfer.NameEdit));
  78.   edit->SetValidator(new TFilterValidator("A-Za-z. "));
  79.   edit = new TEdit(this, IDC_SS, sizeof(transfer.SSEdit));
  80.   edit->SetValidator(new TPXPictureValidator("###-##-####"));
  81.   edit = new TEdit(this, IDC_EMPID, sizeof(transfer.IDEdit));
  82.   edit->SetValidator(new TRangeValidator(1, 999));
  83.   edit = new TEdit(this, IDC_DEPT, sizeof(transfer.DeptEdit));
  84.   edit->SetValidator(new TPXPictureValidator("Sales,Dev,Mfg"));
  85.   edit = new TEdit(this, IDC_SECURITY, sizeof(transfer.SecEdit));
  86.   edit->SetValidator(new TPXPictureValidator("11,12,13,14,15"));
  87.   new TCheckBox(this, IDC_FTIME, 0);
  88.   new TCheckBox(this, IDC_PERMANENT, 0);
  89.   new TCheckBox(this, IDC_EXEMPT, 0);
  90.   CustomEdit = new TEdit(this, IDC_EDIT2, sizeof(transfer.CustomEdit));
  91.   TValidator* v = new TPXPictureValidator("------", true);
  92.   v->UnsetOption(voOnAppend);
  93.   CustomEdit->SetValidator(v);
  94.  
  95.   TransferBuffer = (void far*)&transfer;
  96. }
  97.  
  98. void
  99. TEmployeeDlg::CmSetCustom()
  100. {
  101.   char buff[40];
  102.   TValidator* v;
  103.   
  104.   GetDlgItemText(IDC_EDIT1, buff, sizeof(buff));
  105.   
  106.   TRY {
  107.     v = new TPXPictureValidator(buff, true);
  108.   }
  109.   CATCH( (TXValidator x) {                    // catches syntax errors
  110.     MessageBox(x.why().c_str(), GetApplication()->GetName(), MB_OK);
  111.     return;
  112.   })
  113.   
  114.   v->UnsetOption(voOnAppend);
  115.   CustomEdit->SetValidator(v);
  116.   CustomEdit->SetFocus();
  117. }
  118.  
  119.  
  120. //
  121. // class TTestWindow
  122. // ~~~~~ ~~~~~~~~~~~
  123. class TTestWindow : public TWindow {
  124.   public:
  125.     TTestWindow(TWindow* parent = 0);
  126.     void CmEmpInput();
  127.  
  128.   private:
  129.     TEmployeeStruct EmployeeStruct;
  130.  
  131.   DECLARE_RESPONSE_TABLE(TTestWindow);
  132. };
  133.  
  134. DEFINE_RESPONSE_TABLE1(TTestWindow, TWindow)
  135.   EV_COMMAND(CM_EMPINPUT, CmEmpInput),
  136. END_RESPONSE_TABLE;
  137.  
  138.  
  139. //
  140. //
  141. //
  142. TTestWindow::TTestWindow(TWindow* parent)
  143. :
  144.   TWindow(parent)
  145. {
  146.   memset(&EmployeeStruct, 0, sizeof EmployeeStruct);
  147. }
  148.  
  149. void
  150. TTestWindow::CmEmpInput()
  151. {
  152.   char empInfo[sizeof(TEmployeeStruct)+ 10 + 11 + 11];
  153.  
  154.   if (TEmployeeDlg(this, IDD_EMPLOYEEINFO, EmployeeStruct).Execute() == IDOK) {
  155.     strcpy(empInfo, EmployeeStruct.NameEdit);
  156.     strcat(empInfo, "\n");
  157.     strcat(empInfo, EmployeeStruct.SSEdit);
  158.     strcat(empInfo, "\n");
  159.     strcat(empInfo, EmployeeStruct.IDEdit);
  160.     strcat(empInfo, "\n");
  161.     strcat(empInfo, EmployeeStruct.DeptEdit);
  162.     strcat(empInfo, "\n");
  163.     strcat(empInfo, EmployeeStruct.SecEdit);
  164.     strcat(empInfo, "\n");
  165.     strcat(empInfo, EmployeeStruct.FullTime ? "FullTime " : "PartTime ");
  166.     strcat(empInfo, EmployeeStruct.Perm ? "Permanent " : "Temporary ");
  167.     strcat(empInfo, EmployeeStruct.Exempt ? "Exempt " : "NonExempt ");
  168.     MessageBox(empInfo, "Information Stored", MB_OK);
  169.   }
  170. }
  171.  
  172. //
  173. // class TValidateApp
  174. // ~~~~~ ~~~~~~~~~~~~
  175. class TValidateApp : public TApplication {
  176.   public:
  177.     TValidateApp() : TApplication("ValidateApp") {}
  178.     void InitMainWindow() {
  179.       EnableCtl3d();
  180.       TFrameWindow* frame = new TFrameWindow(0, "Validate Dialog Input",
  181.         new TTestWindow);
  182.       frame->AssignMenu(200);
  183.       SetMainWindow(frame);
  184.     }
  185. };
  186.  
  187. int
  188. OwlMain(int /*argc*/, char* /*argv*/ [])
  189. {
  190.   return TValidateApp().Run();
  191. }
  192.